package baidu.reader.common.ui.components
{
    import baidu.ui.controls.*;

    public class EllipsisLabelButton extends LabelButton
    {
        private var _designatedWidth:Number;
        protected var _ellipsis:Boolean;
        protected var _ellipsisIndex:int = -1;
        protected var _tail:String = "..";

        public function EllipsisLabelButton()
        {
            return;
        }

        override public function set width(param1:Number) : void
        {
            this._designatedWidth = width;
            super.width = param1;
            return;
        }

        override protected function drawLayout() : void
        {
            super.drawLayout();
            this.determineText();
            super.drawLayout();
            return;
        }

        protected function determineText() : void
        {
            var _loc_1:String = null;
            var _loc_2:String = null;
            var _loc_3:String = null;
            if (textField.textWidth > this._designatedWidth)
            {
                _loc_1 = _label;
                if (this._ellipsisIndex > (_loc_1.length - 1) || this._ellipsisIndex < -_loc_1.length)
                {
                    trace("Error：参数 " + this._ellipsisIndex + " 不合法，不再允许范围。");
                    return;
                }
                if (this._ellipsisIndex < 0)
                {
                    textField.text = this._tail + _loc_1.slice(_loc_1.length + this._ellipsisIndex + 1, _loc_1.length);
                    if (textField.textWidth > this._designatedWidth - 4)
                    {
                        trace("Error：参数 " + this._ellipsisIndex + " 不合法，保留的字符过多。");
                        return;
                    }
                }
                else
                {
                    textField.text = _loc_1.slice(0, this._ellipsisIndex) + this._tail;
                    if (textField.textWidth > this._designatedWidth - 4)
                    {
                        trace("Error：参数 " + this._ellipsisIndex + " 不合法，保留的字符过多。");
                        return;
                    }
                }
                textField.text = _label + this._tail;
                while (textField.textWidth > this._designatedWidth - 4)
                {
                    
                    if (this._ellipsisIndex < 0)
                    {
                        _loc_2 = _loc_1.slice(0, _loc_1.length + this._ellipsisIndex);
                        _loc_3 = _loc_1.slice(_loc_1.length + this._ellipsisIndex + 1, _loc_1.length);
                    }
                    else
                    {
                        _loc_2 = _loc_1.slice(0, this._ellipsisIndex);
                        _loc_3 = _loc_1.slice((this._ellipsisIndex + 1), _loc_1.length);
                    }
                    _loc_1 = _loc_2 + _loc_3;
                    label = _loc_2 + this._tail + _loc_3;
                    if (_loc_1.length == 0)
                    {
                        break;
                    }
                }
            }
            return;
        }

    }
}
